/**
 * 表单对象核心js
 * @wu.i
 */
var qryPager;
(function(scope) {
	var FormTpl = Base.extend({
		constructor : function(attribute) {
			attribute= attribute || {};
			this.param ={};
			jQuery.extend(this.param,attribute);
			this.form_id = attribute['form_id'];
			
		},
		setFormId:function(form_id){ //设置表单id
			this.form_id = form_id;
		},
		record_click:function(record_data){ // 点击记录
			jQuery.extend(this.param,record_data);
			commonJS.setInputDomain(this.param,this.form_id);
			this.resetStatus();
		},
		resetStatus:function(){ //点击重置按钮
			this.param.action_type ="";
			this.setDisabled('0');
		},
		retsetValues:function(){
			var context =$("#"+this.form_id) || $("body"); 
			if(typeof(context) =="string")
				context =$("#"+context);
			$("[fieldType='db'][type!='radio']",context).val("");
		},
		setValue:function(dbfield,value){
			var context =$("#"+this.form_id) || $("body"); 
			var currJq=$("[fieldType='db'][dbfield='"+dbfield+"']",context);
			if(currJq && currJq.length>0){
				if((currJq[0].tagName=='INPUT' && currJq[0].type !='radio' ) || currJq[0].tagName=='SELECT' || currJq[0].tagName=='TEXTARES'){
					currJq.val(value);
				}else if(currJq[0].tagName=='INPUT' && currJq[0].type =='radio'   ){
						var currJq2=$("[dbField='"+dbfield+"'][fieldType='db'][type='radio'][value='"+value+"']",context);
						currJq2.attr("checked","checked");
				}else{
					currJq.html(value);
				}
			}
		},
		add:function(){ //点击新增按钮
			this.param.action_type ="A";
			this.setDisabled('1');
			this.retsetValues();
		
		},
		mod:function(param){ // 点击修改按钮
			jQuery.extend(this.param,param);
			commonJS.setInputDomain(this.param,this.form_id);
			this.param.action_type ="M";
			this.setDisabled('1');
		},
		del:function(){ // 点击删除按钮
			this.param.action_type ="D",me=this;
			if(!confirm("是否确定删除信息？"))
			    return;
			if(typeof(this.before_del) =="function")
				this.before_del();
			var params = commonJS.getInputDomain(this.form_id);
			jQuery.extend(this.param,params);
			Service.asExcute(this.param["service_name"],this.param.method, [this.param], function (reply){
	         	me.after_del(reply);
			})
		},
		after_del:function(reply){
			//TODO 子类实现
		},
		after_save:function(reply){
			//TODO 子类实现
		},
		setDisabled:function(type){//设置为不可编辑
			var context =$("#"+this.form_id) || $("body"); 
			if(type=="0"){
				$("[fieldType='db']",context).attr("disabled",true);
			}
			else
				$("[fieldType='db']",context).removeAttr("disabled");
		},
		save:function(){ //点击保存调用
			var me =this;
			if(!commonJS.validate())
				return;
			if(typeof(this.before_save) =="function")
				this.before_save();
			var params = commonJS.getInputDomain(this.form_id);
			jQuery.extend(this.param,params);
			if(!this.param.action_type){
				pop({"text":"请选择修改信息"});
				return;
			}
			Service.asExcute(this.param["service_name"],this.param.method, [this.param], function (reply){
	         	me.after_save(reply);
			})
		}
	})
	window.FormTpl =FormTpl;
}(window));
